package servlet;

import entity.Student;
import service.StudentService;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "FindStudentByIdServlet",urlPatterns = "/findstudentbyid")
public class FindStudentByIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String sid = request.getParameter("sid");
        System.out.println("获取到的学号为：" + sid);

        StudentService studentService = new StudentService();
        List<Student> students = studentService.findStudentByIdService(sid);
        request.setAttribute("students",students);
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("student.jsp");
        requestDispatcher.forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
